package com.shop2cn.iapi.agentproducts.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.activitymgt.parameter.AddactivityBean;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.SelectionActivityListBean;
import com.shop2cn.iapi.agentproducts.service.SelectionActivityListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
/**
*选货中心活动列表Test
*FreeMaker Template自动生成代码
*/
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AgentProductCallServiceV2;
@TestSuite
public class Ts_SelectionActivityList{
	private static SelectionActivityListBean selectionactivitylistBean;
	private static SelectionActivityListCall selectionactivitylistCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("选货中心活动列表Test");
	}

	@Before
	public void caseUp() {
		selectionactivitylistBean=new SelectionActivityListBean();
		selectionactivitylistCall=new SelectionActivityListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(selectionactivitylistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	// 渠道商
	private static int rootUserId = 501428441;
	// 渠道商->代理商1
	private static int agentUserId1 = 501428443;
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SelectionActivityList_001() {
		Logger.start(true,"查询可以继承的活动，成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					"", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//创建限时抢活动
			AddactivityBean initProductaddactivity = AgentProductCallServiceV2.initAgenttActivity(rootUserId, productId,0,null);
			
			Integer activityId = AgentProductCallServiceV2.agentProductaddactivity(initProductaddactivity);
			Thread.sleep(5000);
			selectionactivitylistBean.setUserId(agentUserId1);
			selectionactivitylistCall.setData(selectionactivitylistBean);
			selectionactivitylistCall.callService();			
			Logger.verifyEquals("200", selectionactivitylistCall.getString("code"), "验证code");
			Logger.verifyEquals(true, selectionactivitylistCall.getJsonObject().toString().indexOf(""+activityId)!=-1, "验证查询到了活动id");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SelectionActivityList_002() {
		Logger.start(true,"根据活动id查询，成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					"", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//创建限时抢活动
			AddactivityBean initProductaddactivity = AgentProductCallServiceV2.initAgenttActivity(rootUserId, productId,0,null);
			Integer activityId = AgentProductCallServiceV2.agentProductaddactivity(initProductaddactivity);
			Thread.sleep(3000);
			selectionactivitylistBean.setUserId(agentUserId1);
			selectionactivitylistBean.setActivityId(activityId);
			selectionactivitylistCall.setData(selectionactivitylistBean);
			selectionactivitylistCall.callService();			
			Logger.verifyEquals("200", selectionactivitylistCall.getString("code"), "验证code");
			
			Logger.verifyEquals(true, selectionactivitylistCall.getJsonObject().toString().indexOf(""+activityId)!=-1, "验证查询到了活动id");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}